﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Rswl.Common.Application.User;

namespace Rswl.Common.Application
{

    public static class JwtExtensions
    {
        public static void CustomJwt(this IServiceCollection services, string Url = "/UserAuthHub")
        {
            RsCode.AspNetCore.JwtExtensions.AddJwt(services);
            services.AddAuthorization(options =>
            {
                options.AddPolicy("admin", policy => policy.Requirements.Add(new AdminRequirement("admin")));
                options.AddPolicy("vip", policy => policy.Requirements.Add(new AdminRequirement("vip")));
            });


            services.AddSingleton<IAuthorizationHandler, AdminRequirementHandler>();
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        }
    }
}
